package me.miencraft.plugin.superlobby;

import me.miencraft.plugin.superlobby.listener.BlockEvent;
import me.miencraft.plugin.superlobby.listener.PlayerEvent;
import me.miencraft.plugin.superlobby.command.MainCommand;
import me.miencraft.plugin.superlobby.command.VisibleCommand;
import me.miencraft.plugin.superlobby.config.MainConfig;
import me.miencraft.plugin.superlobby.config.SpawnConfig;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;

public final class SuperLobby extends JavaPlugin {

    public static SuperLobby instance;
    public static MainConfig mainConfig;
    public static SpawnConfig spawnConfig;

    private static Placeholder placeholder;

    @Override
    public void onEnable() {
        instance = this;
        mainConfig = new MainConfig(this);
        spawnConfig = new SpawnConfig(this);
        registerCommand("SuperLobby", new MainCommand());
        registerCommand("Visible", new VisibleCommand());
        getServer().getPluginManager().registerEvents(new PlayerEvent(), this);
        getServer().getPluginManager().registerEvents(new BlockEvent(), this);

        if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
            placeholder = new Placeholder();
            placeholder.register();
        }

    }

    @Override
    public void onDisable() {
        if (placeholder != null) {
            placeholder.unregister();
        }
    }

    private void registerCommand(String name, CommandExecutor executor) {
        PluginCommand command = getCommand(name);
        if (command == null) {
            getLogger().warning("无法注册命令：" + name);
            return;
        }
        command.setExecutor(executor);
    }

}
